﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace System.Windows
{
    internal class ElementNaming
    {
        private ElementNaming()
        {

        }

        private static ElementNaming _Instance = null;

        public static ElementNaming Default
        {
            get
            {
                if (_Instance == null) _Instance = new ElementNaming();
                return _Instance;
            }
        }

        private long            timerId = 0;
        private long            controlId = 0;

        /// <summary>
        /// Hack to support programmatically added Storyboards
        /// </summary>
        /// <returns>A unique Storyboard ID relative to the page</returns>
        public string GetTimerName()
        {
            return String.Format("Timer{0}", timerId++);
        }

        public string GetControlName(string typePrefix)
        {
            return String.Format("{0}{1}", typePrefix, controlId++);
        }

        public string NameObject(DependencyObject depObject)
        {
            object name = depObject.GetValue(FrameworkElement.NameProperty);
            if (name == null || String.IsNullOrEmpty(name.ToString()))
            {
                name = GetControlName(depObject.GetType().Name);
                depObject.SetValue(FrameworkElement.NameProperty, name);
            }

            return name.ToString();
        }
    }
}
